﻿//-----------------------------------------------------------------------
// <copyright file="MessageIntervalToTextConverterHelper.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
namespace ChatBox.UI.ValueConverters
{
    using System.Globalization;

    /// <summary>
    /// Helper class for work common to the PrivateMessageIntervalToTextConverter and PublicMessageIntervalToTextConverter
    /// </summary>
    public static class MessageIntervalToTextConverterHelper
    {
        /// <summary>
        /// Make the display text
        /// </summary>
        /// <param name="currentValue">the current value</param>
        /// <param name="minValue">the minimum value</param>
        /// <param name="maxValue">the maximum value</param>
        /// <returns>the display text</returns>
        public static string MakeTextFromIntervalValue(double currentValue, double minValue, double maxValue)
        {
            string message;

            if (currentValue < minValue)
            {
                message = "Too frequent";
            }
            else if (currentValue == minValue)
            {
                message = "Most frequent";
            }
            else if (currentValue == maxValue)
            {
                message = "Most infrequent";
            }
            else if (currentValue > maxValue)
            {
                message = "Too infrequent";
            }
            else
            {
                double range = maxValue - minValue;
                double oneSixth = minValue + (range / 6);
                double oneThird = minValue + (range / 3);
                double twoThirds = minValue + (range * 2 / 3);

                if (currentValue < oneSixth)
                {
                    message = "Very frequent";
                }
                else if (currentValue < oneThird)
                {
                    message = "Frequent";
                }
                else if (currentValue < twoThirds)
                {
                    message = "Moderate";
                }
                else
                {
                    message = "Infrequent";
                }
            }

            double seconds = currentValue / 1000;
            return string.Format(CultureInfo.InvariantCulture, "Every {0:0.0} seconds: {1}", seconds, message);
        }
    }
}
